package com.sh.web.models;

import com.sh.bean.Resfood;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class MyPageBean<T> {
    // 请求查询的条件
    private int pageno =1;
    private int pagesize=5;
    private String sortby = "fid";
    private String sort = "desc";

    // 查询的结果
    private long total;
    private List<T> records;

    // 计算的数据
    private int totalpages;
    private int pre;  //上一页
    private int next;  //下一页;

    // 查询的参数  例如： 根据 菜名查询
    private Resfood resfood;

    public void calculate(){
        long totalPages = this.total%this.pagesize==0? this.total/this.pagesize : this.total/this.pagesize+1;
        this.totalpages = (int)totalPages;
        if ( pageno <=1 ) {
            pre = 1;
        }else {
            pre = pageno-1;
        }

        if( pageno == totalpages){
            next = (int)totalpages;
        }else {
            next = pageno+1;
        }

    }

}
